************data processing*********
cd E:\data\cooperation\patent\ndata\internet_patent

/*variable list*/
use draft,clear
collin wdi_internetuse yr_sch lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse wbgi_gee ///
ciri_polpris lgdppc wdi_telephone fe_cultdiv taxburden fincialfreedom open monetaryfreedom ///
al_ethnic wdi_trade vdem_corr kun_wiqreco_all urbaniz laborfreedom  ///
fh_fotpsc wdi_internetserv fh_rol une_pee al_language

**the main analysis***
use final_sys,clear
/*label the variabls of the data*/
label var lpat_uspt "Log of the patent grants"
label var lpop_dnst "Log of population density (people per sq. km of land area)"
label var wbgi_pse "Political stability"
label var fh_ipolity2 "Level of democracy (Freedom House/Imputed Polity)"
label var hf_efiscore "Economic freedom index"
label var lgdppc "Log of GDP per capita, PPP (constant 2005 international $)"
label var fe_cultdiv "Cultural diversity"
label var wdi_telephone "Telephone lines (per 100 people)"
label var ciri_polpris "Political imprisonment"
label var taxburden "Tax burden"
label var open "Economic openness"
label var wbgi_gee "Government efficiency"
label var yr_sch_ter "Average years of tertiary schooling attained"
label var fincialfreedom "Financial freedom"
label var wdi_internetuse "Internet users (per 100 people)"
label var polit_sys "Political system"
label var bb_int "Fixed broadband subscriptions"
label var ljur_art "Scientific and technical journal articles"
des 
egen id = group(countrycode)
replace regioncode="LCN" if regioncode=="NAC"
gen region=1
label var region "region area"
replace region=1 if regioncode=="EAS"
replace region=2 if regioncode=="ECS"
replace region=3 if regioncode=="LCN"
replace region=4 if regioncode=="MEA"
replace region=5 if regioncode=="SAS"
replace region=6 if regioncode=="SSF"
gen lint_2=wdi_internetuse^2
gen yr_sch_2=yr_sch_ter^2
label var yr_sch_2 "The square of average years of tertiary schooling attained"
label var lint_2 "The square of internet users (per 100 people)"
save internet_patent,repalce


********************main data analysis*******************************************
use internet_patent,clear
xtset id year

/*1.statisitcal description*/
sum lpat_uspt wdi_internetuse yr_sch_ter lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse wbgi_gee ///
ciri_polpris lgdppc wdi_telephone fe_cultdiv taxburden fincialfreedom open  polit_sys bb_int ljur_art /*table 1*/
 
/*collin test*/
collin wdi_internetuse yr_sch_ter lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse wbgi_gee ///
ciri_polpris lgdppc wdi_telephone fe_cultdiv taxburden fincialfreedom open  /*table 2*/

/*unit root test*/
 xtunitroot fisher lpat_uspt, dfuller lags(3) drift


*****fgls****
xtgls lpat_uspt  wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore  ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone fe_cultdiv i.year i.region , panels(hetero)
est store gls

/*non lag*/
xtreg lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone ,fe 
est store fe
/*random effect*/
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone ,re
est store re
/*lag of the dependent variable*/
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone ,fe 
est store fe1
/*time tread*/
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone i.year, fe
est store fe2
esttab  re fe fe1 fe2 gls, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(0 3) label(N R-squared ))  /*table 3*/
  
hausman fe1 fe,sigmamore 
hausman re fe,sigmamore
hausman fe2 fe,sigmamore

**********fe model with different status***********************
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store fe1
xtreg lpat_uspt L.lpat_uspt L.wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store fe2
xtreg lpat_uspt L.lpat_uspt wdi_internetuse lint_2 yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store fe3
xtreg lpat_uspt L.lpat_uspt wdi_internetuse lint_2 yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone i.year, fe
est store fe4
esttab fe1 fe2 fe3 fe4, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(0 3) label(N R-squared ))  /*table 4*/
**************************group analysis**********************************
*********democracy analysis*****/*table 5*/
preserve
**high level
keep if group==1
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone ,fe
est store high_demo
esttab  high_demo , cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(1 3) label(Observations Adj-R-Square))
restore
preserve
******low level
keep if group==0
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store low_demo
esttab  low_demo , cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(1 3) label(Observations Adj-R-Square))
restore
gen group_lpat_uspt=group*wdi_internetuse
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store all_demo
xtreg lpat_uspt L.lpat_uspt group_lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store all1_demo
esttab  all_demo all1_demo, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(1 3) label(Observations Adj-R-Square))

**********political system*************
preserve
keep if polit_sys==0 /*president*/
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store high_demo
esttab  high_demo , cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(1 3) label(Observations Adj-R-Square))
restore


preserve
keep if polit_sys==1 /*Parliamentary*/
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store low_demo
esttab  low_demo , cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(1 3) label(Observations Adj-R-Square))
restore

gen inter=polit_sys*wdi_internetuse
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store all_demo
xtreg lpat_uspt L.lpat_uspt wdi_internetuse inter yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store all1_demo
esttab  all_demo all1_demo, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(1 3) label(Observations Adj-R-Square))


***************robust test*************
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store fe
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse ///
wbgi_gee ciri_polpris lgdppc wdi_telephone taxburden fincialfreedom open,fe 
est store fe1
esttab  fe fe1, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(1 3) label(Observations Adj-R-Square))




*****************analyze the rd_GPDP***************
use rd,clear
egen id = group(countrycode)
xtset id year
xtreg rd_GDP lgdppc,fe
est store fe
esttab  fe , cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(1 3) label(Observations Adj-R-Square))














